package com.hd.service.impl;

import com.hd.mapper.PermissionMapper;
import com.hd.mapper.RoleMapper;
import com.hd.pojo.Role;
import com.hd.service.RoleService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by 1 on 2017/11/15.
 */
@Service("roleService")
@Transactional
public class RoleServiceImpl implements RoleService{

    @Resource
    private RoleMapper roleMapper;

    @Resource
    private PermissionMapper permissionMapper;

    @Override
    public Role getRoleByRoleId(Integer roleId) {
        return roleMapper.getRoleByRoleId(roleId);
    }

    @Override
    public List<Role> searchRole() {
        return roleMapper.list();
    }

    @Override
    public void addRole(Role role) {
        roleMapper.add(role);
    }

    @Override
    public void updateRole(Role role) {
        roleMapper.update(role);
    }

    @Override
    public void deleteRole(Integer roleId) {
        roleMapper.delete(roleId);
        permissionMapper.deleteByRoleId(roleId);
    }
}
